package tech.aistar.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.scripting.xmltags.SetSqlNode;
import org.apache.ibatis.session.SqlSession;
import tech.aistar.mapper.ProductMapper;
import tech.aistar.model.entity.Product;
import tech.aistar.service.IProductService;
import tech.aistar.util.MyBatisUtil;

import java.util.List;

public class ProductServiceImpl implements IProductService {

    @Override
    public PageInfo<Product> findAll(Integer pageNow, Integer pageSize) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        ProductMapper productMapper = sqlSession.getMapper(ProductMapper.class);

        Page<Product> pageHelper = PageHelper.startPage(pageNow,pageSize);

        List<Product> products = productMapper.findAll();
        PageInfo<Product> pageInfo = new PageInfo<>(products);
        MyBatisUtil.closeSqlSession(sqlSession);

        return pageInfo;
    }
}
